//登录
$('.login').on('click', function () {
    let url_=$(this).attr("data-mode")
    $.ajax({
        url: './'+url_,
        type: 'POST',
        data: {
            UserPassword: $("#floatingPassword").val(),
            UserID: $("#floatingInput").val()
        },
        success: function (data) {
            console.log(data);
            if (data.code == 0) {
                alert('登录成功')
                if(url_=='login_admin'){
                window.location.href = './admin/head.html';

            }else{
                window.location.href = './';

            }
            }

            else {
                alert('登录失败')
            }
        }
    })
})

//注册
$('#sign').on('click', function () {
    var picture = new FormData();
    picture.append('file', $("#picture")[0].files[0])
    // console.log($("#picture")[0].files[0].type.split('/')[1]);
    $.ajax({
        url: './regisstered',
        type: 'POST',
        data: {
            UserPassword: $("#floatingPassword").val(),
            UserID: $("#floatingInput").val(),
            UserName: $("#floatingName").val(),
        },
        success: function (data) {
            console.log(data);
            if (data.code == 0) {
                $.ajax({
                    url: './picture',
                    type: 'POST',
                    data: picture,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        alert('注册成功')
                        window.location.href = './';
                    }
                })
            }
            if (data.code == 1) {
                alert('账号已被注册')
            } else if (data.code == -1) {
                alert('账号只能未纯数字')
            }
            else {
                alert('注册失败')
            }
        }
    })


})

//返回
$('#reture').on('click', function () {
    window.location.href = window.origin;
})